package dongdongmovie.controller;

import com.dongdongmovie.pojo.TMovie;
import com.dongdongmovie.service.TMovie_Service;
import jdk.nashorn.internal.ir.ReturnNode;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("Skip")
public class Skip {

    //注入service
    @DubboReference
    private TMovie_Service tMovie_service;
    @Autowired
    private RedisTemplate redisTemplate;

    //跳转到首页
    @RequestMapping("homepage")
    public String homepage() {
        return "index";
    }

    //跳转到登录注册页面
    @RequestMapping("tzloginregister")
    public String tzloginregister() {
        return "loginregister";
    }

    //跳转分类栏位页面
    @RequestMapping("tzfenlei")
    public String tzfenlei(Integer id, HttpServletRequest request) {
        if (id != null && id == 9999){
            Object vipUser = request.getSession().getAttribute("VipUser");
            if (vipUser == null){
                    return "loginregister";
            }

        }
        request.getSession().setAttribute("fenlei", id);
        return "movie";
    }

    //跳转详情页面
    @RequestMapping("tzxiangqing")
    public String tzxiangqing(Integer id, Model m) {
        TMovie tMovie = tMovie_service.showbyId(id);
        m.addAttribute("tMovie", tMovie);
        return "moviedetail";
    }

    //跳转搜索页面
    @RequestMapping("sousuo")
    public String sousuo(String movieName, Model m) {
        m.addAttribute("movieName", movieName);
        return "search";
    }

    //跳转播放页面
    @RequestMapping("tzbofang")
    public String tzbofang(Integer id, Model m) {
        TMovie tMovie = tMovie_service.showbyId(id);
        String s = "shuju";
        redisTemplate.opsForZSet().incrementScore(s,tMovie,1);
        m.addAttribute("tMovie", tMovie);
        return "moving";
    }

    //存入typeid
    @ResponseBody
    @RequestMapping("typeid")
    public void typeid(Integer typeid, HttpServletRequest request) {
        if (typeid != 0) {
            request.getSession().setAttribute("typeid", typeid);
        } else
            request.getSession().removeAttribute("typeid");
    }

    //存入typeid
    @ResponseBody
    @RequestMapping("areaid")
    public void areaid(Integer areaid, HttpServletRequest request) {
        if (areaid != 0) {
            request.getSession().setAttribute("areaid", areaid);
        } else
            request.getSession().removeAttribute("areaid");
    }

    //存入typeid
    @ResponseBody
    @RequestMapping("yearsid")
    public void yearsid(Integer yearsid, HttpServletRequest request) {
        if (yearsid != 0) {
            request.getSession().setAttribute("yearsid", yearsid);
        } else
            request.getSession().removeAttribute("yearsid");
    }
}
